package com.yowasa.xiuxian.util;


import com.google.common.collect.Lists;
import com.yowasa.xiuxian.entity.mys.MysComponent;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;


public class ComponentUtil {


    public static List<List<MysComponent>> genComponentList(Integer i,MysComponent... mysComponents) {
        List<MysComponent> componentList = Arrays.asList(mysComponents);
        List<List<MysComponent>> partition = Lists.partition(componentList, i);
        return partition;
    }

    public static  List<List<MysComponent>> getComponentList(String tag,Integer integer,List<String> collect) {
        List<MysComponent> list = new ArrayList<>();
        AtomicReference<Integer> i = new AtomicReference<>(1);
        collect.forEach(e -> {
            MysComponent component = new MysComponent(i.get()+"",2,e,tag+e);
            i.getAndSet(i.get() + 1);
            list.add(component);
        });
        MysComponent[] mysComponents = list.toArray(new MysComponent[]{});
        List<List<MysComponent>> lists = genComponentList(integer, mysComponents);
        return lists;
    }
}
